//
//  ViewController.m
//  RQDropDownMenuDemo
//
//  Created by 蜂巢网络科技 on 2017/6/22.
//  Copyright © 2017年 fengchao. All rights reserved.
//

#import "ViewController.h"
#import "RQDropDownMenu.h"
@interface ViewController ()<RQDropDownMenuDataSource,RQDropDownMenuDelegate>
{
    NSMutableArray *_data1;
    NSMutableArray *_data2;
    NSMutableArray *_data3;
    NSArray *_titles;
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _titles = @[@"结算方式",@"智能排序",@"智能排序",@"距离范围"];
    _data1 = [NSMutableArray arrayWithObjects:@"豹子头", @"大刀关胜", @"入云龙", @"玉麒麟", @"黑旋风",nil];
    _data2 = [NSMutableArray arrayWithObjects:@"智能排序", @"离我最近", @"评价最高", @"最新发布", @"人气最高", @"价格最低", @"价格最高", nil];
    _data3 = [NSMutableArray arrayWithObjects:@"不限人数", @"双人餐", @"3~4人餐", @"单人餐", @"双人餐", @"3~4人餐", @"不限人数", @"双人餐", @"3~4人餐",nil];
    
    RQDropDownMenu *menu = [[RQDropDownMenu alloc] initWithOrigin:CGPointMake(0, 20) andHeight:45];
    menu.indicatorColor = [UIColor colorWithRed:175.0f/255.0f green:175.0f/255.0f blue:175.0f/255.0f alpha:1.0];
    menu.separatorColor =[UIColor redColor];
    menu.textColor = [UIColor colorWithRed:83.f/255.0f green:83.f/255.0f blue:83.f/255.0f alpha:1.0f];
    menu.dataSource = self;
    menu.delegate = self;
    [self.view addSubview:menu];
}

#pragma Mark - RQDropDownMenuDataSource
// 组数
- (NSInteger)numberOfColumnsInMenu:(RQDropDownMenu *)menu {
    
    return 4;
}

// 分组的标题
- (NSString *)menu:(RQDropDownMenu *)menu titleForColumn:(NSInteger)column{
    
    return _titles[column];
}

// 返回 每组子菜单下有多少条数据
- (NSInteger)menu:(RQDropDownMenu *)menu numberOfRowsInColumn:(NSInteger)column section:(NSInteger)section
{
    if (column == 0) {
        return _data1.count;
    }else if (column == 1) {
        return _data2.count;
   
    }else if(column == 2){
        if (section == 0) {
            return _data1.count;
        }else if (section == 1){
            return _data2.count;
        }else{
            return _data3.count;
        }
    }else{
        if (section == 0) {
            return _data2.count;
        }else{
            return _data1.count;
        }
    }
}

// 返回 每组子菜单下每条数据是什么
- (NSString *)menu:(RQDropDownMenu *)menu titleForRowAtIndexPath:(RQIndexPath *)indexPath {
    
    if (indexPath.column == 0) {
        return _data1[indexPath.row];
    }else if (indexPath.column == 1) {
        return _data2[indexPath.row];
    }else if (indexPath.column == 2){ // collectiView分组
        
        if (indexPath.section == 0) {
            return _data1[indexPath.row];
        }else if (indexPath.section == 1){
            return _data2[indexPath.row];
        }else{
            return _data3[indexPath.row];
        }
    }else { // collectiView分组
        
        if (indexPath.section == 0) {
            return _data2[indexPath.row];
        }else{
            return _data1[indexPath.row];
        }
    }
}

- (BOOL)menu:(RQDropDownMenu *)menu isMultipleAtIndexPath:(RQIndexPath *)indexPath
{
    if (indexPath.column == 2 || indexPath.column ==3) {
        
        if (indexPath.section==0) {
            return YES;
        }else{
            return NO;
        }
    }
    
    return NO;
}

// 是否需要显示为UICollectionView 默认为否
-(BOOL)displayByCollectionViewInColumn:(NSInteger)column{
    
    if (column==2 || column ==3) {
        return YES;
    }
    return NO;
}

// 返回collectView有多少分组
- (NSInteger)numberOfSectionInCollectionViewMenu:(RQDropDownMenu *)menu column:(NSInteger)column
{
    if (column == 2) {
        return 3;
    }else{
        return 2;
    }
}
// 返回collectView每组的标题
- (NSString *)menu:(RQDropDownMenu *)menu titleForSection:(NSInteger)section column:(NSInteger)column;
{
    if (column == 2) {
        return _titles[section];
    }else{
        return _titles[section];

    }
}

#pragma Mark - RQDropDownMenuDelegate
- (void)menu:(RQDropDownMenu *)menu didSelectRowAtIndexPath:(RQIndexPath *)indexPath
{
    if (indexPath.column == 1) {
        NSLog(@"row %@",_data2[indexPath.row]);
    }
}

// 确认
- (void)menu:(RQDropDownMenu *)menu column:(NSInteger)column didSelectCollectionCellWithDictionary:(NSDictionary *)selectDict
{
    NSLog(@"selectDictselectDict %@",selectDict);
}

// 重置
- (void)menu:(RQDropDownMenu *)menu resetDataWithColumn:(NSInteger)column
{
    
}
@end
